package com.huobao.yunying.activitys;

import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Act_YijianFankui extends HuobaoBaseActivity {
	@ViewInject(R.id.tv_1)
	private TextView tv_tel;
	@ViewInject(R.id.tv_2)
	private TextView tv_qq;

	@ViewInject(R.id.edt_name)
	private EditText edt_name;
	@ViewInject(R.id.edt_tel)
	private EditText edt_tel;
	@ViewInject(R.id.edt_content)
	private EditText edt_content;

	@Override
	protected int getContentView() {
		// TODO Auto-generated method stub
		return R.layout.layout_yijianfankui;
	}

	@Override
	protected String getTitleText() {
		// TODO Auto-generated method stub
		return "意见反馈";
	}

	@Override
	protected void init() {
		// TODO Auto-generated method stub
		tv_tel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (phone_mob == null)
					return;
				Uri uri = Uri.parse("tel:" + phone_mob);
				Intent intent = new Intent(Intent.ACTION_DIAL, uri);
				startActivity(intent);
			}
		});
		getData();
	}

	String phone_mob;

	private void getData() {
		Map<String, String> map = HttpUtil.getParams("app", "news", "act", "custome");
		Http.getInstant().sendRequest(context, map, new HttpListener() {

			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				jsonObject = jsonObject.getJSONObject("retval");
				phone_mob = jsonObject.getString("phone_mob");
				String im_qq = jsonObject.getString("im_qq");
				tv_tel.setText(phone_mob);
				tv_qq.setText(im_qq);
			}

			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub

			}
		});
	}

	public void onSubmitClick(View v) {
		String name = edt_name.getText().toString().trim();
		String tel = edt_tel.getText().toString().trim();
		String content = edt_content.getText().toString();
		if (TextUtils.isEmpty(name)) {
			Toast.makeText(context, "清输入姓名", Toast.LENGTH_SHORT).show();
			return;
		}
		if (TextUtils.isEmpty(tel)) {
			Toast.makeText(context, "清输入电话", Toast.LENGTH_SHORT).show();
			return;
		}
		if (TextUtils.isEmpty(content)) {
			Toast.makeText(context, "清输入内容", Toast.LENGTH_SHORT).show();
			return;
		}
		Map<String, String> map = HttpUtil.getParams("app", "buyerorder", "act", "feedback", "username", name,
				"phone_mob", tel, "remark", content);
		Http.getInstant().sendRequest(context, map, new HttpListener() {
			
			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				Toast.makeText(context, jsonObject.getString("retval"), Toast.LENGTH_SHORT).show();
				finish();
			}
			
			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub
				
			}
		});
	}

}
